package edu.neumont.pro180._2009_q2.chess;

import edu.neumont.pro180._2009_q2.Player;
import edu.neumont.pro180._2009_q2.Square;
import edu.neumont.pro180._2009_q2.interfaces.ICommand;
import edu.neumont.pro180._2009_q2.interfaces.IGamePiece;

public class PawnPromotion implements ICommand
{
	private Square from;
	private Square to;
	private IGamePiece newPiece;
	private IGamePiece oldPiece;
	private IGamePiece captured;
	private Player player;
	
	public PawnPromotion(Square from, Square to, Class<? extends IGamePiece> newPieceClass )
	{
		this.from = from;
		this.to = to;
		try {
			newPiece = newPieceClass.newInstance();
		} catch (Exception e) {
		}
		this.oldPiece = from.getGamePiece();
		this.captured = to.getGamePiece();
		this.player = oldPiece.getPlayer();
	}
	
	@Override
	public void execute() {
		player.removeGamePiece(oldPiece);
		player.addGamePiece(newPiece);
		newPiece.getMove(to).execute();
		if( captured != null )
			captured.getMove( null ).execute();
	}

	@Override
	public void undo() {
		player.removeGamePiece(newPiece);
		player.addGamePiece(oldPiece);
		oldPiece.getMove(from).execute();
		if( captured != null )
			captured.getMove( to ).execute();
	}

	@Override
	public Square getDestination() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Square getOriginalSquare() {
		// TODO Auto-generated method stub
		return null;
	}

}
